package com.aoyama.kafka.base.demo03;

import org.apache.kafka.clients.consumer.ConsumerRecord;
import org.springframework.kafka.annotation.KafkaListener;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * 重点： 批量消费
 *
 * # 设置批量消费
 * spring.kafka.listener.type=batch
 * # 批量消费每次最多消费多少条消息
 * spring.kafka.consumer.max-poll-records=50
 */
@Component
public class BatchConsume02 {


    @KafkaListener(id = "consumer2",groupId = "defaultConsumerGroup", topics = "topic5")
    public void onMessage3(List<ConsumerRecord<?, ?>> records) {
        System.out.println(">>>批量消费一次，records.size()="+records.size());
        for (ConsumerRecord<?, ?> record : records) {
            System.out.println(record.value());
        }
    }

}
